-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(servicecatalogappregistry): initial L2 construct for Application #15140
Conversation
Service Catalog AppRegistry application construct initial base version. Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing Testing done ------------------ * `yarn build && yarn test` * `yarn integ` Co-authored-by: Dillon Ponzo <dponzo18@gmail.com> ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Regarding ARN, the arn format is different from standard convention for this resource, however the |
packages/@aws-cdk/aws-servicecatalogappregistry/test/application.test.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just a few minor comments.
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-servicecatalogappregistry/test/integ.application.ts
Outdated
Show resolved
Hide resolved
Addressing comments from PR Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! A couple of super-minor issues.
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts
Outdated
Show resolved
Hide resolved
* Validates length is between allowed min and max lengths. | ||
*/ | ||
public static validateLength(resourceName: string, inputName: string, minLength: number, maxLength: number, inputString?: string): void { | ||
if (inputString !== undefined && (inputString.length < minLength || inputString.length > maxLength)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One important note that I forgot to include in the Portfolio PR.
If the value provided is a dynamic CloudFormation expression, like a Parameter Ref
, we should skip this validation. You can figure out whether a given value is a dynamic expression using the Token.isUnresolved()
method.
This needs to be verified with a unit test.
Could you also retroactively change this in the Portfolio class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it. Followed convention from S3 test to make sure it doesn't throw validation error even when given an invalid value as token, which I think nicely covers the functionality.
Will make quick PR for adding this to our portfolio construct in aws-servicecatalog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, would there be any interest/support in making some input validation apart of core
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created PR for this in servicecatalog: #15208
packages/@aws-cdk/aws-servicecatalogappregistry/lib/private/validation.ts
Outdated
Show resolved
Hide resolved
Addressing minor formatting comments from PR review. Added functionality to skip validation if we are passed a token for properties, and added unit tests for those cases Testing done ------------------ * `yarn build && yarn lint && yarn test` Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
*/ | ||
public static validateRegex(resourceName: string, inputName: string, regex: RegExp, inputString?: string): void { | ||
if (!cdk.Token.isUnresolved(inputString) && inputString !== undefined && !regex.test(inputString)) { | ||
throw new Error(`Invalid ${inputName} for resource ${resourceName}, must match regex pattern ${regex}, got: '${inputString}'`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not truncating this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't originally do it because it validates length first, but we truncate the string to 100 chars while the name can be longer, so probably would be better parity to do that hear as well. Will add
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-servicecatalogappregistry/lib/private/validation.ts
Outdated
Show resolved
Hide resolved
const tokenDescription = cdk.Lazy.string({ produce: () => 'token description'.repeat(1000) }); | ||
expect(() => { | ||
new appreg.Application(stack, 'MyApplication', { | ||
applicationName: 'myApplication', | ||
description: tokenDescription, | ||
}); | ||
}).not.toThrow(/Invalid application description for resource/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use a CloudFormation Parameter here instead of a Lazy? Using Lazy
like that makes the test look weird (unrealistic).
I would also just assert on the template contents:
const tokenDescription = cdk.Lazy.string({ produce: () => 'token description'.repeat(1000) }); | |
expect(() => { | |
new appreg.Application(stack, 'MyApplication', { | |
applicationName: 'myApplication', | |
description: tokenDescription, | |
}); | |
}).not.toThrow(/Invalid application description for resource/); | |
const param = new cdk.CfnParameter(stack, 'Param'); | |
new appreg.Application(stack, 'MyApplication', { | |
applicationName: 'myApplication', | |
description: param.valueAsString, | |
}); | |
expect(stack).toHaveResourceLike('AWS::ServiceCatalogAppRegistry::Application', { | |
Description: { | |
Ref: 'Param', | |
}, | |
}); |
Looks like we're missing a similar test for applicationName
, BTW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to test template for the fields, both name and description
Updating unit tests to properly test that token inputs do end up getting created in template and not just validating it throwing a specific error Testing done ------------------ * `yarn build && yarn lint && yarn test` Co-authored-by Dillon Ponzo <dponzo18@gmail.com>
… into appregistry_l2_construct merging branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 2 super minor last comments.
packages/@aws-cdk/aws-servicecatalogappregistry/lib/application.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
…n.ts Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Nice turnaround on the ARN parsing. Updated the test and messaging to match our other resources for consistency. |
const arn = cdk.Stack.of(scope).splitArn(applicationArn, cdk.ArnFormat.SLASH_RESOURCE_SLASH_RESOURCE_NAME); | ||
const applicationId = arn.resourceName; | ||
|
||
if (!applicationId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed this to match our SC construct error check and messaging
/** | ||
* Enforces a particular physical application name. | ||
*/ | ||
readonly applicationName: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW - you called this displayName
in Portfolio
. Any reason you went with a different name in Application
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual cfn term in Portfolio
is DisplayName
, see here. For application it is just name
hence applicationName
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't want to make this consistent across the ServiceCatalog constructs that exhibit this behavior (display name + auto-generated ID)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
…aws#15140) Service Catalog AppRegistry application construct initial base version. Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing. Testing done ------------------ * `yarn build && yarn test` * `yarn integ` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
…aws#15140) Service Catalog AppRegistry application construct initial base version. Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing. Testing done ------------------ * `yarn build && yarn test` * `yarn integ` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
…aws#15140) Service Catalog AppRegistry application construct initial base version. Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing. Testing done ------------------ * `yarn build && yarn test` * `yarn integ` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* Co-authored-by: Dillon Ponzo <dponzo18@gmail.com>
Service Catalog AppRegistry application construct initial base version.
Please note the ARNS for this construct have two '/' in them hence the slightly different ARN parsing.
Testing done
yarn build && yarn test
yarn integ
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
Co-authored-by: Dillon Ponzo dponzo18@gmail.com